<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/vhuichen.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/vhuichen.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/vhuichen.ico">
  <link rel="mask-icon" href="/vhuichen.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"vhuichen.github.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.13.0","exturl":false,"sidebar":{"position":"left","display":"display","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}}</script><script src="/js/config.js"></script>

    <meta property="og:type" content="website">
<meta property="og:title" content="vhuichen">
<meta property="og:url" content="https://vhuichen.github.io/page/3/index.html">
<meta property="og:site_name" content="vhuichen">
<meta property="og:locale">
<meta property="article:author" content="vhuichen">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://vhuichen.github.io/page/3/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":true,"isPost":false,"lang":"zh-Hans","comments":"","permalink":"","path":"page/3/index.html","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>vhuichen</title>
  






  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">vhuichen</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">记录、分享</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section">Home</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section">Archives</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section">About</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="vhuichen"
      src="/images/vhuichen.jpg">
  <p class="site-author-name" itemprop="name">vhuichen</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">86</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/" class="post-title-link" itemprop="url">Swift 什么是ABI稳定、模块稳定</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2020-05-10 00:00:00" itemprop="dateCreated datePublished" datetime="2020-05-10T00:00:00+08:00">2020-05-10</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2021-07-04 01:18:40" itemprop="dateModified" datetime="2021-07-04T01:18:40+08:00">2021-07-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="什么是ABI"><a href="#什么是ABI" class="headerlink" title="什么是ABI"></a>什么是ABI</h3><p>应用程序二进制接口（Application Binary Interface，ABI）是指两程序模块间的接口，通常其中一个程序模块会是库或操作系统所提供的服务，而另一边的模块则是用户所运行的程序。<br>ABI 约定了我们的应用程序怎样获取数据以及操作数据。应用程序就是通过这些ABI跟系统通信的。</p>
<h3 id="ABI稳定"><a href="#ABI稳定" class="headerlink" title="ABI稳定"></a>ABI稳定</h3><p>Swift 5.0 版本之前，应用程序打包时，都会将 Swift 标准库导入到二进制包中，原因是不同的 Swift 版本之间差异大，ABI接口不兼容。<br>Swift 5.0 开始 ABI 以及稳定。从 5.0 版本开始 Swift 共用一个 ABI 接口，所以从 5.0 版本开始打包时就不需要将 SWift 基础库打进二进制包中，此时iOS系统以及包含了这些基础库，这样做的好处是之一就是包体积变小了，启动时间变少了，更省内存了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">事实上，打包时还是会包含 Swift 基础库，原因是在 iOS 12.2 之前依然需要 Swift 基础库，但之后的版本 App Store 会自动移除。</span><br></pre></td></tr></table></figure>

<h3 id="模块稳定"><a href="#模块稳定" class="headerlink" title="模块稳定"></a>模块稳定</h3><p>Swift 5.1 之前，不同的版本生成的 Module（模块）只能在对应的版本上运行，不然就会出现以下错误</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler</span><br></pre></td></tr></table></figure>

<p>而从 5.1 版本开始， <code>Module Stability</code> 允许 5.1 版本打的 Module 在 5.1 之后的任意版本运行。</p>
<p>开启 <code>Module Stability</code> 后，Framework 引入了一个全新的文件夹 <code>.swiftmodule</code>，包含 <code>.swiftinterface</code> 和 <code>.swiftmodule</code> 文件，<code>swiftinterface</code> 文件作为 <code>swiftmodule</code> 的一个补充，用来描述 <code>module</code> 公开接口的文本文件，并且不受编译器版本限制，既通过 <code>swiftinterface</code> 文件可以将 Swift 6 打包的 framework 在 swift 7 版本下运行。</p>
<p>需要设置 </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//BUILD_LIBRARY_FOR_DISTRIBUTION</span><br><span class="line">//Ensures that your libraries are built for distribution. </span><br><span class="line">//For Swift, this enables support for library evolution and generation of a module interface file.</span><br><span class="line">Build Libraries for Distribution = YES</span><br></pre></td></tr></table></figure>

<p>开启 <code>Build Libraries for Distribution</code> 后编译的文件如下<br><img src="https://gitee.com/vhuichen/images/raw/master/img/20210513181627.png"></p>
<p>如果不开启 <code>Build Libraries for Distribution</code> ，那么编译后会少了 <code>swiftinterface</code>， 此时的 <code>Module</code> 是受版本限制的。</p>
<h5 id="什么是-Library-Evolution"><a href="#什么是-Library-Evolution" class="headerlink" title="什么是 Library Evolution"></a>什么是 Library Evolution</h5><p>开启 <code>Library Evolution</code> 后，也就是<code>Build Libraries for Distribution</code>，当一个框架依赖另一个框架时，如果另一个框架发生改动，那么不需要重新编译第一个框架。也就是更新第二个框架不需要重新编译第一个框架。<br>类似于 <code>@frozen</code> ?</p>
<h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><p><a target="_blank" rel="noopener" href="https://onevcat.com/2019/02/swift-abi/">Swift ABI 稳定对我们到底意味着什么</a><br><a target="_blank" rel="noopener" href="https://swift.org/blog/abi-stability-and-more/">ABI Stability and More</a><br><a target="_blank" rel="noopener" href="https://www.donnywals.com/what-is-module-stability-in-swift-and-why-should-you-care/">What is Module Stability in Swift and why should you care?</a></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2020/05/iOS/CocoaPods%E4%B9%8BProfile/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/05/iOS/CocoaPods%E4%B9%8BProfile/" class="post-title-link" itemprop="url">CocoaPods之Profile</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2020-05-03 00:00:00" itemprop="dateCreated datePublished" datetime="2020-05-03T00:00:00+08:00">2020-05-03</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2021-05-11 00:02:20" itemprop="dateModified" datetime="2021-05-11T00:02:20+08:00">2021-05-11</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="Profile-详解"><a href="#Profile-详解" class="headerlink" title="Profile 详解"></a>Profile 详解</h1><h2 id="0x00"><a href="#0x00" class="headerlink" title="0x00"></a>0x00</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">//限制最低版本，不限制的话可能会报错</span><br><span class="line">platform :ios, &#x27;9.0&#x27;</span><br><span class="line"></span><br><span class="line">//不提示第三方库的警告，如果有组件的</span><br><span class="line">inhibit_all_warnings!</span><br><span class="line"></span><br><span class="line">//使用静态库</span><br><span class="line">use_modular_headers!</span><br><span class="line">//动态库</span><br><span class="line">use_frameworks!</span><br><span class="line"></span><br><span class="line">//支持的swift版本</span><br><span class="line">supports_swift_versions &#x27;&gt;= 5.0&#x27;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">//声明使用的安装方法和选项，install! 函数只能调用一次</span><br><span class="line">install!</span><br><span class="line">//目前只允许通过 cocoapods 安装</span><br><span class="line">install! &#x27;cocoapods&#x27;,</span><br><span class="line"></span><br><span class="line">支持的key ,显示的是默认值</span><br><span class="line"></span><br><span class="line">//清理pod没有使用的所有文件</span><br><span class="line">:clean =&gt; true</span><br><span class="line"></span><br><span class="line">//是否复制pod的target</span><br><span class="line">:deduplicate_targets =&gt; true</span><br><span class="line"></span><br><span class="line">//是否生成uuid</span><br><span class="line">:deterministic_uuids =&gt; true</span><br><span class="line"></span><br><span class="line">//是否将安装的pods集成到项目中</span><br><span class="line">//如果设置为false, Pods将被下载并安装到Pods/目录中，但不会集成到项目中</span><br><span class="line">:integrate_targets =&gt; true</span><br><span class="line"></span><br><span class="line">//锁定pods的源文件</span><br><span class="line">:lock_pod_sources =&gt; true</span><br><span class="line"></span><br><span class="line">//多个源包含相同名称和版本的Pod时发出警告</span><br><span class="line">:warn_for_multiple_pod_sources =&gt; true</span><br><span class="line"></span><br><span class="line">//</span><br><span class="line">:share_schemes_for_development_pods =&gt; false</span><br><span class="line"></span><br><span class="line">//禁用CocoaPods脚本阶段的输入和输出路径(复制框架和复制资源)</span><br><span class="line">//可以解决修改了私有库代码后，无法立即生效的问题</span><br><span class="line">:disable_input_output_paths =&gt; false</span><br><span class="line"></span><br><span class="line">//是否保留所有pod的文件结构，包括外部pod源。</span><br><span class="line">//默认情况下，Pod源的文件结构仅为开发Pod保留。</span><br><span class="line">//设置:preserve_pod_file_structure为true将始终保存文件结构。</span><br><span class="line">:preserve_pod_file_structure =&gt; false</span><br><span class="line"></span><br><span class="line">//是否为每个pod目标生成一个项目，而不是创建一个Pods.xcodeproj，此选项将为嵌套在Pods.xcodeproj下的每个pod目标生成一个项目。</span><br><span class="line">//使用此选项可以加快编译速度</span><br><span class="line">:generate_multiple_pod_projects =&gt; false</span><br><span class="line"></span><br><span class="line">//是否仅启用自上次安装以来已更改的重新生成目标及其关联项目。</span><br><span class="line">:incremental_installation =&gt; false</span><br><span class="line"></span><br><span class="line">//是否跳过生成Pods.xcodeproj，只执行依赖项解析和下载。</span><br><span class="line">:skip_pods_project_generation</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="0x01-关键字"><a href="#0x01-关键字" class="headerlink" title="0x01 关键字"></a>0x01 关键字</h2><h4 id="pod"><a href="#pod" class="headerlink" title="pod"></a>pod</h4><p>指定项目的依赖项。依赖项需求由Pod的名称和版本需求列表(可选)定义。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;Objection&#x27;, &#x27;0.9&#x27;</span><br><span class="line">//</span><br><span class="line">= 0.1，版本0.1。  </span><br><span class="line">&gt; 0.1，任何高于0.1的版本。</span><br><span class="line">&gt;= 0.1，版本0.1和任何更高版本。</span><br><span class="line">&lt; 0.1，任何低于0.1的版本。</span><br><span class="line">&lt;= 0.1，版本0.1和任何较低版本。</span><br><span class="line">~&gt; 0.1.2，版本0.1.2及以上到版本0.2，不含0.2。该操作符基于你在版本需求中指定的最后一个组件工作。这个例子等于&gt;= 0.1.2与&lt; 0.2.0相结合，并且总是匹配与你的需求相匹配的最新已知版本。</span><br><span class="line">~ &gt; 0.1.3-beta.0，Beta版和release发行版本为0.1.3，发行版本为0.2(不包括0.2)。用破折号(-)分隔的组件将不考虑版本要求。</span><br></pre></td></tr></table></figure>

<h4 id="configurations"><a href="#configurations" class="headerlink" title="configurations"></a>configurations</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;PonyDebugger&#x27;, :configurations =&gt; [&#x27;Debug&#x27;, &#x27;Beta&#x27;]</span><br><span class="line">pod &#x27;PonyDebugger&#x27;, :configuration =&gt; &#x27;Debug&#x27;</span><br></pre></td></tr></table></figure>

<h4 id="modular-headers"><a href="#modular-headers" class="headerlink" title="modular_headers"></a>modular_headers</h4><p>模块化，当你使用 use_modular_headers! 属性时，可以从模块头中排除特定的Pod</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;SSZipArchive&#x27;, :modular_headers =&gt; false</span><br></pre></td></tr></table></figure>

<h4 id="source-path"><a href="#source-path" class="headerlink" title="source path"></a>source path</h4><p>源，默认情况下，在全局级别指定的源按照指定依赖项匹配的顺序进行搜索。这种行为可以通过指定依赖项的来源来改变特定的依赖项</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;PonyDebugger&#x27;, :source =&gt; &#x27;https://github.com/CocoaPods/Specs.git&#x27;</span><br><span class="line">pod &#x27;AFNetworking&#x27;, :path =&gt; &#x27;~/Documents/AFNetworking&#x27;</span><br><span class="line">pod &#x27;AFNetworking&#x27;, :git =&gt; &#x27;https://github.com/gowalla/AFNetworking.git&#x27;, :branch =&gt; &#x27;dev&#x27;</span><br><span class="line">pod &#x27;AFNetworking&#x27;, :git =&gt; &#x27;https://github.com/gowalla/AFNetworking.git&#x27;, :tag =&gt; &#x27;0.7.0&#x27;</span><br><span class="line">pod &#x27;AFNetworking&#x27;, :git =&gt; &#x27;https://github.com/gowalla/AFNetworking.git&#x27;, :commit =&gt; &#x27;082f8319af&#x27;</span><br><span class="line">pod &#x27;JSONKit&#x27;, :podspec =&gt; &#x27;https://example.com/JSONKit.podspec&#x27;</span><br></pre></td></tr></table></figure>

<h4 id="Subspecs"><a href="#Subspecs" class="headerlink" title="Subspecs"></a>Subspecs</h4><p>当通过它的名字安装Pod时，它将安装podspec中定义的所有默认的子规范。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;QueryKit/Attribute&#x27;</span><br><span class="line">pod &#x27;QueryKit&#x27;, :subspecs =&gt; [&#x27;Attribute&#x27;, &#x27;QuerySet&#x27;]</span><br></pre></td></tr></table></figure>

<h4 id="testspecs"><a href="#testspecs" class="headerlink" title="testspecs"></a>testspecs</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;AFNetworking&#x27;, :testspecs =&gt; [&#x27;UnitTests&#x27;, &#x27;SomeOtherTests&#x27;]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="abstract-target"><a href="#abstract-target" class="headerlink" title="abstract_target"></a>abstract_target</h4><p>定义一个新的抽象目标，可用于方便的目标依赖项继承。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">abstract_target &#x27;Networking&#x27; do</span><br><span class="line">  pod &#x27;AlamoFire&#x27;</span><br><span class="line">  </span><br><span class="line">  target &#x27;ShowsiOS&#x27; do</span><br><span class="line">    pod &#x27;ShowWebAuth&#x27;</span><br><span class="line">  end</span><br><span class="line"> </span><br><span class="line">  target &#x27;ShowsTV&#x27; do</span><br><span class="line">    pod &#x27;ShowTVAuth&#x27;</span><br><span class="line">  end</span><br><span class="line">  </span><br><span class="line">end</span><br></pre></td></tr></table></figure>
<h4 id="def"><a href="#def" class="headerlink" title="def"></a>def</h4><p>预定义模块</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">def debug_pods</span><br><span class="line">  pod &#x27;LookinServer&#x27;, :configurations =&gt; [&#x27;Debug&#x27;]</span><br><span class="line">  pod &#x27;MLeaksFinder&#x27;, :configurations =&gt; [&#x27;Debug&#x27;]</span><br><span class="line">end</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2020/04/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%E4%BF%AE%E9%A5%B0%E7%AC%A6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2020/04/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%E4%BF%AE%E9%A5%B0%E7%AC%A6/" class="post-title-link" itemprop="url">Swift 访问权限修饰符</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2020-04-27 00:00:00" itemprop="dateCreated datePublished" datetime="2020-04-27T00:00:00+08:00">2020-04-27</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2021-07-03 22:47:28" itemprop="dateModified" datetime="2021-07-03T22:47:28+08:00">2021-07-03</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="Swift-访问权限修饰符"><a href="#Swift-访问权限修饰符" class="headerlink" title="Swift 访问权限修饰符"></a>Swift 访问权限修饰符</h2><p>swift 的设计目标之一就是安全类型语言（Designed for Safety），所以多几个<code>访问修饰符</code>也是合情合理的。<br>访问修饰符可以用来修饰<code>属性</code>、<code>方法</code>、<code>类</code>、<code>结构体</code></p>
<h4 id="private"><a href="#private" class="headerlink" title="private"></a>private</h4><p>只能在当前类里使用，不允许外部或者其子类访问。如果用来修饰类、结构体，那么作用相当于<code>fileprivate</code></p>
<blockquote>
<p>private(set) 表示禁止设置，即只读，可访问</p>
</blockquote>
<h4 id="fileprivate"><a href="#fileprivate" class="headerlink" title="fileprivate"></a>fileprivate</h4><p>只能在当前的源文件里使用</p>
<h4 id="internal（默认）"><a href="#internal（默认）" class="headerlink" title="internal（默认）"></a>internal（默认）</h4><p>可以在源代码所在的模块使用  </p>
<h4 id="public"><a href="#public" class="headerlink" title="public"></a>public</h4><p>可以在模块之外使用，但不可以在其它模块中重写和继承</p>
<h4 id="open"><a href="#open" class="headerlink" title="open"></a>open</h4><p>可以在模块之外使用，也可以在其它模块中重写和继承</p>
<h3 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h3><p><strong>在一个 Framework 里，既有 Swift 又有 OC 代码时，编译器会将 Swift 和 OC 分别当成一个 Module 。Swift 代码除了使用关键字 <code>@objc</code> 外，还必须使用 <code>public </code> 级别的关键字才能被同一个 Framework 里的 OC 代码使用</strong></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2019/05/2019/05/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BB%A3%E7%A0%81%E4%BC%98%E5%8C%96/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2019/05/2019/05/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BB%A3%E7%A0%81%E4%BC%98%E5%8C%96/" class="post-title-link" itemprop="url">记一次代码优化</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2019-05-03 00:00:00" itemprop="dateCreated datePublished" datetime="2019-05-03T00:00:00+08:00">2019-05-03</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2021-04-12 22:35:19" itemprop="dateModified" datetime="2021-04-12T22:35:19+08:00">2021-04-12</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E9%87%8D%E6%9E%84/" itemprop="url" rel="index"><span itemprop="name">重构</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h2><blockquote>
<p>下拉刷新某个主页面，需要刷新这个主页面里的所有子页面，每个子页面都是一个独立的模块，也就是要等到所有的模块都请求完成时，主页面的刷新才能结束,并执行一系列相应的操作。   </p>
</blockquote>
<p>以上就是一个完成的需求，OK，开始写代码，第一版的代码思路是这样的</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">assign</span>) <span class="built_in">NSInteger</span> dataCallbackCount;</span><br><span class="line"></span><br><span class="line">- (<span class="type">void</span>)refreshView &#123;</span><br><span class="line">	<span class="keyword">self</span>.dataCallbackCount = <span class="number">0</span>;</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData0lWithComplete:^&#123;</span><br><span class="line">		<span class="keyword">self</span>.dataCallbackCount++;</span><br><span class="line">		[<span class="keyword">self</span> shouldEndRefresh:dataCallbackCount];</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData1lWithComplete:^&#123;</span><br><span class="line">		<span class="keyword">self</span>.dataCallbackCount++;</span><br><span class="line">		[<span class="keyword">self</span> shouldEndRefresh:dataCallbackCount];</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData2lWithComplete:^&#123;</span><br><span class="line">		<span class="keyword">self</span>.dataCallbackCount++;</span><br><span class="line">		[<span class="keyword">self</span> shouldEndRefresh:dataCallbackCount];</span><br><span class="line">	&#125;];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="type">void</span>)shouldEndRefresh:(<span class="built_in">NSInteger</span>)count &#123;</span><br><span class="line">    <span class="keyword">if</span> (count &gt;= <span class="number">3</span>) &#123;</span><br><span class="line">        [<span class="keyword">self</span>.refreshView endRefresh];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>第一版的代码有个问题，dataCallbackCount 属性和 shouldEndRefresh 方法 都是刷新方法内部才需要使用的，现在都变成类内部全局的了，其他的方法也可以使用这个属性和方法，而且 dataCallbackCount 还一直占用内存，这是不应该的。<br>我们知道block可以捕获变量，方法也可以用block代替。那么第二版改动如下：  </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="type">void</span>)refreshView &#123;</span><br><span class="line">    __block <span class="built_in">NSInteger</span> dataCallbackCount = <span class="number">0</span>;</span><br><span class="line">	 </span><br><span class="line">    <span class="type">void</span> (^shouldEndRefresh)(<span class="type">void</span>) = ^(<span class="type">void</span>) &#123;</span><br><span class="line">        <span class="keyword">if</span> (++dataCallbackCount &gt;= <span class="number">3</span>) &#123;</span><br><span class="line">            [<span class="keyword">self</span>.refreshView endRefresh];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData0lWithComplete:^&#123;</span><br><span class="line">		shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData1lWithComplete:^&#123;</span><br><span class="line">		shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData2lWithComplete:^&#123;</span><br><span class="line">		shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>第二版我们将所有的代码都放到一个方法内了，同时也将 self.dataCallbackCount++; 放到了block内部，避免多次调用。dataCallbackCount 这个变量也会在结束刷新后释放内存，对于外部来说只需要调用 refreshView 就可以了，这样显得内聚很多。<br>但是仔细看的话，又会发现现在的 dataCallbackCount 也只是 shouldEndRefresh 内部需要使用而已 对于 [self.viewModel fetchxxx] 方法来说也应该是不可见的，但显然目前的这种写法是可见的。于是第三版改动如下：   </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="type">void</span>)refreshView &#123;</span><br><span class="line">    <span class="type">void</span> (^_shouldEndRefresh)(<span class="type">void</span>) = ^(<span class="built_in">NSInteger</span> dataCallbackCountMax) &#123;</span><br><span class="line">        __block <span class="built_in">NSInteger</span> dataCallbackCount = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">return</span> ^&#123;</span><br><span class="line">            <span class="keyword">if</span> (++dataCallbackCount &gt;= dataCallbackCountMax) &#123;</span><br><span class="line">                [<span class="keyword">self</span>.refreshView endRefresh];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;(<span class="number">3</span>);</span><br><span class="line">    </span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData0lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData1lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData2lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>优化结束，如果需要优化的话可以将 [self.refreshView endRefresh]; 方法抽出来。最终代码如下： </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="type">void</span>)refreshViewWithCallBack:(<span class="type">void</span>(^)(<span class="type">void</span>))callback &#123;</span><br><span class="line">    <span class="type">void</span> (^_shouldEndRefresh)(<span class="type">void</span>) = ^(<span class="built_in">NSInteger</span> dataCallbackCountMax) &#123;</span><br><span class="line">        __block <span class="built_in">NSInteger</span> dataCallbackCount = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">return</span> ^&#123;</span><br><span class="line">            <span class="keyword">if</span> (++dataCallbackCount &gt;= dataCallbackCountMax) &#123;</span><br><span class="line">                callback ? callback() : <span class="literal">nil</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">    &#125;(<span class="number">3</span>);</span><br><span class="line">    </span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData0lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData1lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">	</span><br><span class="line">	[<span class="keyword">self</span>.viewModel fetchData2lWithComplete:^&#123;</span><br><span class="line">		_shouldEndRefresh();</span><br><span class="line">	&#125;];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>-END-</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2018/08/2018/08/iOS%20%E6%95%B0%E6%8D%AE%E5%8E%BB%E9%87%8D%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2018/08/2018/08/iOS%20%E6%95%B0%E6%8D%AE%E5%8E%BB%E9%87%8D%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95/" class="post-title-link" itemprop="url">iOS 数据去重的几种方法</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2018-08-04 00:00:00" itemprop="dateCreated datePublished" datetime="2018-08-04T00:00:00+08:00">2018-08-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2018-08-12 20:00:32" itemprop="dateModified" datetime="2018-08-12T20:00:32+08:00">2018-08-12</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/iOS%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">iOS基础</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="基本类型数据去重（4种方法）"><a href="#基本类型数据去重（4种方法）" class="headerlink" title="基本类型数据去重（4种方法）"></a>基本类型数据去重（4种方法）</h2><p>1、利用 NSDictionary key 的唯一性<br>2、利用 NSSet 的特性，数据不能重复<br>3、利用 NSArray 的 containsObject 方法<br>4、利用 NSArray 的 valueForKeyPath 方法，传入的 keyPath 为 <code>@distinctUnionOfObjects.self</code></p>
<h3 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h3><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">NSArray</span> *dataArray = @[<span class="string">@&quot;a&quot;</span>,<span class="string">@&quot;b&quot;</span>,<span class="string">@&quot;c&quot;</span>,<span class="string">@&quot;d&quot;</span>,<span class="string">@&quot;e&quot;</span>,<span class="string">@&quot;f&quot;</span>,<span class="string">@&quot;g&quot;</span>,</span><br><span class="line">                       <span class="string">@&quot;b&quot;</span>,<span class="string">@&quot;d&quot;</span>,<span class="string">@&quot;a&quot;</span>];</span><br><span class="line">                       </span><br><span class="line"><span class="built_in">NSMutableDictionary</span> *dict = [<span class="built_in">NSMutableDictionary</span> dictionary];</span><br><span class="line"><span class="keyword">for</span>(<span class="built_in">NSString</span> *str <span class="keyword">in</span> dataArray) &#123;</span><br><span class="line">    [dict setValue:str forKey:str];</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@&quot;dict = %@&quot;</span>,[dict allKeys]);</span><br><span class="line"></span><br><span class="line"><span class="built_in">NSSet</span> *set = [<span class="built_in">NSSet</span> setWithArray:dataArray];</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@&quot;set = %@&quot;</span>,[set allObjects]);</span><br><span class="line"></span><br><span class="line"><span class="built_in">NSMutableArray</span> *array = [<span class="built_in">NSMutableArray</span> array];</span><br><span class="line"><span class="keyword">for</span> (<span class="built_in">NSString</span> *str <span class="keyword">in</span> dataArray) &#123;</span><br><span class="line">    <span class="keyword">if</span> (![array containsObject:str]) &#123;</span><br><span class="line">        [array addObject:str];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@&quot;array = %@&quot;</span>,array);</span><br><span class="line"></span><br><span class="line"><span class="built_in">NSArray</span> *keyPathArray = [dataArray valueForKeyPath:<span class="string">@&quot;@distinctUnionOfObjects.self&quot;</span>];</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@&quot;keyPathArray = %@&quot;</span>,keyPathArray);</span><br></pre></td></tr></table></figure>
<p>通过上面4中方法均可过滤掉重复数据。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2018/08/2018/08/iOS%20%E6%95%B0%E6%8D%AE%E5%8E%BB%E9%87%8D%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2018/07/2018/07/iOS%E5%BC%80%E5%8F%91%E4%B9%8B%20anchorPoint/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2018/07/2018/07/iOS%E5%BC%80%E5%8F%91%E4%B9%8B%20anchorPoint/" class="post-title-link" itemprop="url">iOS开发之 anchorPoint</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2018-07-18 00:00:00" itemprop="dateCreated datePublished" datetime="2018-07-18T00:00:00+08:00">2018-07-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2018-08-12 10:07:52" itemprop="dateModified" datetime="2018-08-12T10:07:52+08:00">2018-08-12</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/iOS%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">iOS开发</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h2><p>将一个视图对象绕设定点旋转</p>
<h3 id="旋转"><a href="#旋转" class="headerlink" title="旋转"></a>旋转</h3><p>当我们需要将一个 View 旋转90°时，可以这样做  </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">self</span>.view.transform = <span class="built_in">CGAffineTransformMakeRotation</span>(M_PI_2);</span><br></pre></td></tr></table></figure>
<p>这时，这个 view 就会绕着“旋转中心”旋转，那么这个“旋转中心”能否自定义呢？肯定是可以的，继续往下看。。。  </p>
<p>我们知道每一个 UIView 内部都关联着一个 CALayer ，而 CALayer 中有一个属性</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* Defines the anchor point of the layer&#x27;s bounds rect, as a point in</span></span><br><span class="line"><span class="comment"> * normalized layer coordinates - &#x27;(0, 0)&#x27; is the bottom left corner of</span></span><br><span class="line"><span class="comment"> * the bounds rect, &#x27;(1, 1)&#x27; is the top right corner. Defaults to</span></span><br><span class="line"><span class="comment"> * &#x27;(0.5, 0.5)&#x27;, i.e. the center of the bounds rect. Animatable. */</span></span><br><span class="line"><span class="keyword">@property</span> <span class="built_in">CGPoint</span> anchorPoint;</span><br></pre></td></tr></table></figure>
<p>这个 anchorPoint 俗称“锚点”，其实也就是上面所说的“旋转中心”。<br>从注释中我们可以看懂，anchorPoint 是一个已经“归一化”的数据，也就是默认值是中心（0.5, 0.5），左上角是（0, 0），右下角是（1, 1）。anchorPoint 是一个以自身为参考系的“归一化”坐标。<br>所以当我们想绕某个点旋转时，只需要将这个点相对于自身的“归一化”坐标赋值给 anchorPoint 就行了。但，事实上当我们改动 anchorPoint 时，发现 layer 也改动了。也就是 anchorPoint 和 frame 之间存在某种关系。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2018/07/2018/07/iOS%E5%BC%80%E5%8F%91%E4%B9%8B%20anchorPoint/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2018/07/2018/07/UITextField%20%E6%B7%BB%E5%8A%A0%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2018/07/2018/07/UITextField%20%E6%B7%BB%E5%8A%A0%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6/" class="post-title-link" itemprop="url">UITextField 添加点击事件</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2018-07-13 00:00:00" itemprop="dateCreated datePublished" datetime="2018-07-13T00:00:00+08:00">2018-07-13</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2018-08-12 09:54:52" itemprop="dateModified" datetime="2018-08-12T09:54:52+08:00">2018-08-12</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/iOS%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">iOS基础</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h2><p>点击 UITextField 没有成为第一响应者，而是触发一个事件。</p>
<h3 id="常规做法-UITapGestureRecognizer"><a href="#常规做法-UITapGestureRecognizer" class="headerlink" title="常规做法 UITapGestureRecognizer"></a>常规做法 UITapGestureRecognizer</h3><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">UITapGestureRecognizer</span> *tap = [[<span class="built_in">UITapGestureRecognizer</span> alloc] initWithTarget:<span class="keyword">self</span> action:<span class="keyword">@selector</span>(tapGesture:)];</span><br><span class="line">[<span class="keyword">self</span>.searchTextField addGestureRecognizer:tap];</span><br><span class="line"></span><br><span class="line">- (<span class="type">void</span>)tapGesture:(<span class="built_in">UIGestureRecognizer</span> *)gesture &#123;</span><br><span class="line">    <span class="built_in">NSLog</span>(<span class="string">@&quot;--%@&quot;</span>, gesture);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这样做可以触发一个事件，同时也成为了第一响应者。那么怎样不让 UITextField 成为第一响应者呢？可以通过委托事件完成  </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">self</span>.searchTextField.delegate = <span class="keyword">self</span>;</span><br><span class="line"></span><br><span class="line">- (<span class="type">BOOL</span>)textFieldShouldBeginEditing:(<span class="built_in">UITextField</span> *)textField &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">NO</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2018/07/2018/07/UITextField%20%E6%B7%BB%E5%8A%A0%E7%82%B9%E5%87%BB%E4%BA%8B%E4%BB%B6/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2018/07/2018/07/iOS%20%E5%9C%B0%E5%9B%BE%E5%AE%9A%E4%BD%8D%E5%9D%90%E6%A0%87%E5%81%8F%E5%B7%AE%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2018/07/2018/07/iOS%20%E5%9C%B0%E5%9B%BE%E5%AE%9A%E4%BD%8D%E5%9D%90%E6%A0%87%E5%81%8F%E5%B7%AE%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/" class="post-title-link" itemprop="url">iOS 地图定位坐标偏差解决方案</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2018-07-09 00:00:00" itemprop="dateCreated datePublished" datetime="2018-07-09T00:00:00+08:00">2018-07-09</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2018-07-17 23:35:00" itemprop="dateModified" datetime="2018-07-17T23:35:00+08:00">2018-07-17</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/iOS%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">iOS开发</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>由于某些原因，国内的经纬度坐标系并不是使用通用的经纬度坐标系。当坐标定位到国内时就会出现偏差，所以我们需要先判断经纬度坐标是否在国内，如果是，则需要先转成国内坐标。</p>
<h3 id="常用坐标系"><a href="#常用坐标系" class="headerlink" title="常用坐标系"></a>常用坐标系</h3><h4 id="WGS84坐标系"><a href="#WGS84坐标系" class="headerlink" title="WGS84坐标系"></a>WGS84坐标系</h4><p>国际坐标，Google地图、苹果地图使用的坐标系。GPS信号直接解析的经纬度信息也是这个坐标系的。</p>
<h4 id="GCJ02坐标系"><a href="#GCJ02坐标系" class="headerlink" title="GCJ02坐标系"></a>GCJ02坐标系</h4><p>中国坐标，高德地图、腾讯地图使用这个坐标系。国内基站定位、WIFI定位获取到的也是 GCJ02 的坐标。</p>
<h4 id="国内的其他坐标系"><a href="#国内的其他坐标系" class="headerlink" title="国内的其他坐标系"></a>国内的其他坐标系</h4><p>还有一些国内的地图，在 GCJ02 坐标的基础上再进行一次加密。例如：百度坐标（BD09）。</p>
<h3 id="iOS-苹果地图开发"><a href="#iOS-苹果地图开发" class="headerlink" title="iOS 苹果地图开发"></a>iOS 苹果地图开发</h3><p>苹果地图在国内使用的是高德地图的数据（GCJ02坐标系），在国外则使用自己的数据（WGS84坐标系）。那么我们应该怎么区分国内外呢？这里有几种方法</p>
<h4 id="1、国家区域判断"><a href="#1、国家区域判断" class="headerlink" title="1、国家区域判断"></a>1、国家区域判断</h4><p>用大量的点将将中国圈出来（港澳台地区要单独出来），然后判断经纬度是否在这个区域内。边界点越多越精确。<br>缺点：数据越多运算量越大，数据少精确度就低。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2018/07/2018/07/iOS%20%E5%9C%B0%E5%9B%BE%E5%AE%9A%E4%BD%8D%E5%9D%90%E6%A0%87%E5%81%8F%E5%B7%AE%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/2/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><span class="page-number current">3</span><a class="page-number" href="/page/4/">4</a><span class="space">&hellip;</span><a class="page-number" href="/page/10/">10</a><a class="extend next" rel="next" href="/page/4/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>

</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2015 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vhuichen</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
